package com.yf.system.config.function;

import com.google.common.base.Predicates;
import com.yf.framework.exception.ServiceException;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Collections;
import java.util.Map;

/**
 * 全局功能配置清单
 * @author bool
 * @date 2020/8/19 20:53
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "config")
public class FunctionConfig {

    /**
     * 功能清单
     */
    private Map<String,Boolean> functions;

    /**
     * 功能是否开启
     * @param key
     * @return
     */
    public boolean hasFunction(String key){
       return this.hasFunction(key, true);
    }

    /**
     * 功能是否开启
     * @param key
     * @return
     */
    public boolean hasFunction(String key, boolean throwable){

        if(functions == null || !functions.containsKey(key) || !functions.get(key)){
            if(throwable) {
                throw new ServiceException("管理员未开启此功能，请联系管理员！");
            }else{
                return false;
            }
        }

        return true;
    }

}
